import Vue from 'vue'
import VueRouter from 'vue-router'
import IndexView from '../views/IndexView.vue'
import HomeView from '../views/HomeView.vue'
import testView from '../views/testView.vue'

Vue.use(VueRouter)

//解决vue路由重复导航错误
// 获取原型对象push函数
const originalPush = VueRouter.prototype.push
// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace
// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location){
return originalPush.call(this , location).catch(err=>err)
}
// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location){
return originalReplace.call(this , location).catch(err=>err)
}

const routes = [
  {
    //重定向
    path:'/',
    redirect:'/index'
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/test',
    name: 'test',
    component: testView
  },
  {
    path: '/index',
    name: 'Index',
    component: IndexView
  },
  {
    path: '/about',
    name: 'about',
    component: ()=>import('../views/AboutView.vue')
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('../pages/loginView.vue')
  },
  {
    path:'/register',
    name:'register',
    component:()=>import('../pages/registerView.vue')
  },
  {
    path:'/bussiness',
    name:'bussiness',
    component:()=>import('../pages/bussinessView.vue')
  },
  {
    path:'/play',
    name:'play',
    component:()=>import('../pages/playView.vue')
  },
  {
    path:'/ticket',
    name:'ticket',
    component:()=>import('../pages/ticketView.vue')
  },
  {
    path:'/service',
    name:'service',
    component:()=>import('../pages/serviceView.vue')
  },
  {
    path:'/museum',
    name:'museum',
    component:()=>import('../pages/museum.vue')
  },
  {
    path:'/trip',
    name:'trip',
    component:()=>import('../pages/tripView.vue')
  },
  {
    path:'/line',
    name:'line',
    component:()=>import('../pages/lineView.vue')
  },
  {
    path:'/tikInfo',
    name:'tikInfo',
    component:()=>import('../pages/tikInfo.vue')
  },
  {
    path:'/order/:id',
    name:'order',
    component:()=>import('../pages/orderView.vue')
  },
  {
    path:'/search/:name',
    name:'search',
    component:()=>import('../pages/searchView.vue')
  },
  {
    path:'/userInfo',
    name:'userInfo',
    component:()=>import('../pages/userInfo.vue')
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
